package com.yanghui.dtracing.plugin.mysql;

import com.yanghui.dtracing.core.match.ClassMatch;
import com.yanghui.dtracing.core.match.NameMatch;
import com.yanghui.dtracing.core.plugin.AbstractClassEnhancePluginDefine;
import com.yanghui.dtracing.core.plugin.IInstanceMethodInterceptPoint;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.ElementMatchers;

public class MysqlDefinition extends AbstractClassEnhancePluginDefine {

    @Override
    public ClassMatch enhanceClass() {
        return new NameMatch("com.mysql.cj.NativeSession");
    }

    @Override
    public IInstanceMethodInterceptPoint[] buildInstanceMethodInterceptPoints() {
        return new IInstanceMethodInterceptPoint[]{
                new IInstanceMethodInterceptPoint(){
                    @Override
                    public ElementMatcher<MethodDescription> buildMethodsMatcher() {
                        return ElementMatchers.named("execSQL");
                    }

                    @Override
                    public String methodInterceptor() {
                        return "com.yanghui.dtracing.plugin.mysql.MysqlInstanceMethodAroundInterceptor";
                    }
                }
        };
    }
}
